function intersect(nums1: number[], nums2: number[]): number[] {
  let arr: number[] = [];
  for (let i = 0; i < nums1.length; i++) {
    let index = nums2.indexOf(nums1[i]);
    if (index !== -1) {
      arr.push(nums1[i]);
      nums2[index] = -1;
    }
  }
  return arr;
}
console.log(intersect([1, 2, 2, 1], [2, 2]));
